package com.netease.nie.facade;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.dto.CreditHistoryDto;
import com.netease.nie.model.CreditHistory;
import com.netease.nie.service.CreditHistoryService;

@Service
public class CreditHistoryFacadeImpl implements CreditHistoryFacade {

	@Autowired
	private CreditHistoryService creditHistoryService;

	public List<CreditHistoryDto> queryCreditHistoryByUserId(long userId) {
		List<CreditHistory> creditHistoryList = creditHistoryService.queryCreditHistoryByUserId(userId);
		if (!creditHistoryList.isEmpty()) {
			int size = creditHistoryList.size();
			List<CreditHistoryDto> creditHistoryDtoList = new ArrayList<>(size);
			CreditHistory creditHistory = null;
			CreditHistoryDto creditHistoryDto = null;
			for (int i = 0; i < size; i++) {
				creditHistory = creditHistoryList.get(i);
				creditHistoryDto = new CreditHistoryDto();

				CopyUtils.copy(creditHistoryDto, creditHistory);

				Integer date = creditHistory.getGenerateDate();
				creditHistoryDto.setDate(String.valueOf(date));

				creditHistoryDtoList.add(creditHistoryDto);
			}
			return creditHistoryDtoList;
		}
		return Collections.emptyList();
	}

}
